Uec3.payableIndexWindow = Ext.extend(Ext.app.Module, {
   	id: 'payable_index',
   	objsCollection:new Ext.util.MixedCollection(true),
   	getObjByKey:function(key){
		return this.objsCollection.get(key);
	},
   /**
    * Initialize this module.
    * This function is called at startup (page load/refresh).
    */
   init : function(initParams){	
   },
   getPanel:function(params) {
   		var module=this;
		var payableArray=new Ext.util.MixedCollection(false);
		var payable_record=Ext.data.Record.create( [ {
			name : 'id',
			type : 'int',
			mapping : 'id'
		}, {
			name : 'companyId',
			type : 'int',
			mapping : 'companyId'
		}, {
			name : 'customerId',
			type : 'int'
		}, {
			name : 'code',
			type : 'string',
			mapping : 'code'
		}, {
			name : 'documentType',
			type : 'int',
			mapping : 'documentType'
		}, {
			name : 'documentId',
			type : 'int',
			mapping : 'documentId'
		}, {
			name : 'documentCode',
			type : 'string',
			mapping : 'documentCode'
		}, {
			name : 'payable',
			type : 'double',
			mapping : 'payable'
		}, {
			name : 'paid',
			type : 'double',
			mapping : 'paid'
		}, {
			name : 'unPaid',
			type : 'double',
			mapping : 'unPaid'
		}, {
			name : 'status',
			type : 'int',
			mapping : 'status'
		}, {
			name : 'gmtCreate',
			type : 'date',
			dateFormat:'Y-m-d H:i:s',
			mapping : 'gmtCreate'
		}, {
			name : 'gmtModify',
			type : 'date',
			dateFormat:'Y-m-d H:i:s',
			mapping : 'gmtModify'
		}, {
			name : 'gmtPaid',
			type : 'date',
			dateFormat:'Y-m-d H:i:s',
			mapping : 'gmtPaid'
		}, {
			name : 'brand',
			type : 'string',
			mapping : 'brand'
		}, {
			name : 'workFlowId',
			type : 'int',
			mapping : 'workFlowId'
		}, {
			name : 'currentorId',
			type : 'int',
			mapping : 'currentorId'
		}, {
			name : 'customerName',
			type : 'string',
			mapping : 'customerName'
		}, {
			name : 'documentTypeVarName',
			type : 'string',
			mapping : 'documentTypeVarName'
		}, {
			name : 'statusVarName',
			type : 'string',
			mapping : 'statusVarName'
		}]);	
		var payable_store=new Ext.data.Store( {
			proxy : new Ext.data.HttpProxy( {
				url :Uec3.App.Constants.homeUrl+'/payable/base!extList.do'
			}),
			pruneModifiedRecords : true,
			baseParams : {
			},
			paramNames : {
				start : "start",
				limit : "limit",
				sort : "sort",
				dir : "dir"
			},
			reader : new Ext.data.JsonReader( {
				totalProperty : 'totalProperty',
				root : 'root'
			}, payable_record)
		});
		module.objsCollection.add("store",payable_store);
		var selectM=new Ext.grid.CheckboxSelectionModel({
				listeners:{
					'beforerowselect':function(obj,rowIndex,keepExisting,record){
						if(record.data.unPaid==0){
							Ext.Msg.alert("警告","请选中未支付完成的单据!");
							return false;
						}
						if(payableArray.length>0){
							if(payableArray.itemAt(0).data.customerId!=record.data.customerId){
								Ext.Msg.alert("警告","请选中相同供应商!");
									return false;
							}
						}
					},
					'rowselect':function (obj,rowIndex,record) {
						payableArray.add(record);
					},
					'rowdeselect':function (obj,rowIndex,record) {
						payableArray.remove(record);
					}
					
				}
			});
		var payable_cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),
			selectM,
			{
			header : '应付款凭证号',
			width : 120,
			sortable : true,
			align:"right",
			dataIndex : 'code'
			}, {
			header : '供应商',
			width : 180,
			sortable : true,
			align:"left",
			dataIndex : 'customerName'
			}, {
			header : '单据号',
			width : 100,
			sortable : true,
			align:"right",
			dataIndex : 'documentCode'
			}, {
			header : '单据类型',
			width : 75,
			sortable : true,
			align:"left",
			dataIndex : 'documentTypeVarName'
			}, {
			header : '应付款',
			width : 120,
			sortable : true,
			align:"right",
			dataIndex : 'payable',
			renderer:showMoney
			}, {
			header : '已付款',
			width : 120,
			sortable : true,
			align:"right",
			dataIndex : 'paid',
			renderer:showMoney
			}, {
			header : '支付状态',
			width : 90,
			align:"left",
			sortable : true,
			dataIndex : 'statusVarName'
			}, {
			header : '创建时间',
			width : 90,
			align:"right",
			sortable : true,
			dataIndex : 'gmtCreate',
			renderer:Ext.util.Format.dateRenderer("Y-m-d")
			}, {
			header : '修改时间',
			width : 90,
			align:"right",
			sortable : true,
			dataIndex : 'gmtModify',
			renderer:Ext.util.Format.dateRenderer("Y-m-d")
			},{
			//id:'payable_gmtPaid',
			header : '付款时间',
			width : 120,
			align:"right",
			sortable : true,
			dataIndex : 'gmtPaid',
			renderer:Ext.util.Format.dateRenderer("Y-m-d")
		}]);
	
		var payable_grid=new Ext.grid.GridPanel({
	        cm:payable_cm,
	        viewConfig : {
				forceFit : true,
				getRowClass : function(record,rowIndex,rowParams,store){
					//禁用数据显示红色
					if(record.data.documentType==3){
						return 'x-grid-record-red';
					}else{
						return '';
					}
					
				}
			},
			store : payable_store,
			//autoExpandColumn:'payable_gmtPaid',
			sm : selectM,
			iconCls : 'icon-grid',
			loadMask : {
				msg : '数据加载中...'
			},
			stripeRows : true,
			autoScroll : true,
			autoload : true,
			height : 350,
			width : '100%',
			listeners : {
			},
			// paging bar on the bottom
			bbar : new Ext.PagingToolbar( {
				pageSize : 10,
				store : payable_store,
				displayInfo : true,
				style : 'align:center',
				displayMsg : '第 {0} - {1} 条  共 {2} 条',
				emptyMsg : "没有记录",
				listeners:{
					//翻页前
					'beforechange':function(){
						//payOperation();
					},
					'change':function(){
						var rowIdArray=[];
						Ext.each(payable_grid.getStore().getRange(),function(spayable){
							Ext.each(payableArray.getRange(),function(payable){
								var rowId=payable_grid.getStore().indexOfId(spayable.id);
								if(rowId!=-1&&spayable.id==payable.id){
									rowIdArray.push(rowId);
								}
							});
						});
						payable_grid.getSelectionModel().selectRows(rowIdArray);
					}
				}
				
			}),
			tbar:new Ext.Toolbar([
				'-',
				{
				text:'支付',
				iconCls : 'icon-payable',
				handler:function(){
					var isError=false;
					//payOperation();//获得选择项数组
					if(payableArray.length==0){
						Ext.Msg.alert("信息","请选记录");
						return;
					}
					var payableIds="";
					payableArray.each(function(payable){
						payableIds+=payable.id+",";
					});
					payableIds=Ext.util.Format.substr(payableIds,0,payableIds.length-1);
					OpenOtherWindow({payableIds:payableIds,customerId:payableArray.first().data.customerId,winId:"auto_"+payableIds});
				
				}
				},
				'-',{
				text:'清空选择',
				iconCls : 'icon-clear',
				handler:function(){
					payableArray.clear();
					payable_grid.getSelectionModel().clearSelections();
				}
				},'-']
			)
		});
		var payable_form_search=new Ext.FormPanel({
			items:[{
			//xtype : 'fieldset',
			border : false,
			layout : 'column',
			style:'padding:0px',
			labelWidth:100,
			items : [{
				layout : 'form',
				items : [{
					xtype : 'textfield',
					name:'textSearchConditions',
					fieldLabel : '模糊查询',
					labelStyle:"text-align:center",
				    width : 200,
		        	emptyText : '多条件可用逗号或者空格隔开!',
		            listeners : {
			         	'specialkey' : function(field, e) {
							if (e.getKey() == Ext.EventObject.ENTER) {
								payable_search();
						  	}
						}
					} 
				}]
			}, {
				layout : 'column',
				style:'margin-left:20px;',
				items : [{
					xtype : 'button',
					text : '查询',
					width:50,
					listeners:{
					'click':payable_search
					}
		   
				},{
			  		xtype:'label',
			  		text:'可查条件:应付款凭证号,供应商,单据号,支付状态',
			  		style:"color:#ff3333;font-size:14px;margin-left:20px;"
			  }]
			}]
			}]
		});
	        /* panel */
		var payable_panel = new Ext.Panel({
			frame : true,
			items : [payable_form_search, payable_grid]
		});
		function payable_search(){
			var obj=payable_form_search.getForm().findField("textSearchConditions").getValue();
			payable_grid.getStore().baseParams.searchConditions=obj;
		    payable_grid.getStore().load();
		}	
		
	function OpenOtherWindow(obj){
		var desktop =Uec3.App.getDesktop();   
		desktop.launchWindowByParam("payInvoice_operation",obj); 
	}
	return payable_panel;
	},
	initEvent:function(){
		var module=this;
		var win=module.getObjByKey("win");
		win.on('show',function(){
			this.getObjByKey("store").load();
		},module,{single:true});
	},
   createWindow : function(params){
   	  var windowId=this.id;
   	  if(params&&params.winId){
   	  	windowId+="_"+params.winId;
   	  }
      var desktop = this.app.getDesktop();   
      var module=this;
      var win = desktop.getWindow(windowId);
      if(!win){
         win = desktop.createWindow({
            id: windowId,
            uecId:windowId,
            title: '应付款列表',
            width: 1000,
            height: 500,
            iconCls: 'acc-icon',
            shim: false,
            moduleObj:module,
            animCollapse: false,
            constrainHeader: true,
            maximizable: true,
            layout: "fit", 
            items:[Ext.isEmpty(params)?this.getPanel():this.getPanel(params)],
            listeners:{
            	'resize':function(win,width,height){
            		var top=this.items.get(0).items.first();
            		var grid=this.items.get(0).items.last();
            		var winMinWidth=1000;
            		var winMinHeight=440;
            		if(width<winMinWidth||height<winMinHeight){
            			win.setWidth(winMinWidth);
            			win.setHeight(winMinHeight);
            			grid.setHeight(winMinHeight-100);
            			//grid.setWidth(winMinWidth-20);
            		}else{
            			grid.setWidth(width-20);
            			grid.setHeight(height-100);
            		}
            	}
            }
         });
         module.objsCollection.add('win',win);
         module.initEvent();
      } 
      win.show();
   }
	});

